<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Qt 4.3: tetrixpiece.js Example File (script/tetrix/tetrixpiece.js)</title>
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top" width="32"><a href="http://www.trolltech.com/products/qt"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></a></td>
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="modules.html"><font color="#004faf">Modules</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
<td align="right" valign="top" width="230"><a href="http://www.trolltech.com"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></a></td></tr></table><h1 align="center">tetrixpiece.js Example File<br /><sup><sup>script/tetrix/tetrixpiece.js</sup></sup></h1>
<pre> TetrixShape = {
     NoShape:0,
     ZShape:1,
     SShape:2,
     LineShape:3,
     TShape:4,
     SquareShape:5,
     LShape:6,
     MirroredLShape:7
 }

 TetrixCoordsTable = [
     [ [ 0,   0 ], [ 0,  0 ], [ 0,  0 ], [ 0,  0 ] ],
     [ [ 0,  -1 ], [ 0,  0 ], [ -1, 0 ], [ -1, 1 ] ],
     [ [ 0,  -1 ], [ 0,  0 ], [ 1,  0 ], [ 1,  1 ] ],
     [ [ 0,  -1 ], [ 0,  0 ], [ 0,  1 ], [ 0,  2 ] ],
     [ [ -1,  0 ], [ 0,  0 ], [ 1,  0 ], [ 0,  1 ] ],
     [ [ 0,   0 ], [ 1,  0 ], [ 0,  1 ], [ 1,  1 ] ],
     [ [ -1, -1 ], [ 0, -1 ], [ 0,  0 ], [ 0,  1 ] ],
     [ [ 1,  -1 ], [ 0, -1 ], [ 0,  0 ], [ 0,  1 ] ]
 ]

 function TetrixPiece()
 {
     this.shape = TetrixShape.NoShape;
 }

 TetrixPiece.prototype.__defineGetter__(
     &quot;shape&quot;,
     function() {
       return this._shape;
     }
 );

 TetrixPiece.prototype.__defineSetter__(
     &quot;shape&quot;,
     function(shape) {
       this._shape = shape;
       this._coords = new Array(4);
       for (var i = 0; i &lt; 4; ++i)
           this._coords[i] = TetrixCoordsTable[shape][i].slice();
     }
 );

 TetrixPiece.prototype.setRandomShape = function() {
     this.shape = Math.floor(((Math.random() * 100000) % 7) + 1);
 }

 TetrixPiece.prototype.getX = function(index) {
     return this._coords[index][0];
 }

 TetrixPiece.prototype.getY = function(index) {
     return this._coords[index][1];
 }

 TetrixPiece.prototype._setX = function(index, x) {
     this._coords[index][0] = x;
 }

 TetrixPiece.prototype._setY = function(index, y) {
     this._coords[index][1] = y;
 }

 TetrixPiece.prototype.__defineGetter__(
     &quot;minX&quot;,
     function() {
         var min = this._coords[0][0];
         for (var i = 1; i &lt; 4; ++i)
             min = Math.min(min, this._coords[i][0]);
         return min;
     }
 );

 TetrixPiece.prototype.__defineGetter__(
     &quot;maxX&quot;,
     function() {
         var max = this._coords[0][0];
         for (var i = 1; i &lt; 4; ++i)
             max = Math.max(max, this._coords[i][0]);
         return max;
     }
 );

 TetrixPiece.prototype.__defineGetter__(
     &quot;minY&quot;,
     function() {
       var min = this._coords[0][1];
       for (var i = 1; i &lt; 4; ++i)
           min = Math.min(min, this._coords[i][1]);
       return min;
     }
 );

 TetrixPiece.prototype.__defineGetter__(
     &quot;maxY&quot;,
     function() {
         var max = this._coords[0][1];
         for (var i = 1; i &lt; 4; ++i)
             max = Math.max(max, this._coords[i][1]);
         return max;
     }
 );

 TetrixPiece.prototype.rotatedLeft = function() {
     var result = new TetrixPiece();
     if (this._shape == TetrixShape.SquareShape) {
         result.shape = this._shape;
         return result;
     }
     result._shape = this._shape;
     for (var i = 0; i &lt; 4; ++i) {
         result._setX(i, this.getY(i));
         result._setY(i, -this.getX(i));
     }
     return result;
 }

 TetrixPiece.prototype.rotatedRight = function() {
     var result = new TetrixPiece();
     if (this._shape == TetrixShape.SquareShape) {
         result.shape = this._shape;
         return result;
     }
     result._shape = this._shape;
     for (var i = 0; i &lt; 4; ++i) {
         result._setX(i, -this.getY(i));
         result._setY(i, this.getX(i));
     }
     return result;
 }</pre>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="30%">Copyright &copy; 2008 <a href="trolltech.html">Trolltech</a></td>
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
<td width="30%" align="right"><div align="right">Qt 4.3.5</div></td>
</tr></table></div></address></body>
</html>
